/* eslint-disable react/self-closing-comp */
import React, { Component } from "react";
import { Card, Col, Spin, Row, Table, Divider } from "antd";
import {
  formFieldOfProvider,
  formFieldOfCustomer,
} from "components/template/widget/unified-select/UnifiedSelect";
import "./style.scss";
import UnifiedTable from "components/template/widget/unified-table/UnifiedTable";
import { formatNumber, messages, deepFullCopy } from "share/common";

class GiftDeclareDetail extends Component {
  getProviderTitle = (provider) => {
    switch (provider.key) {
      case "option1":
        return "现有供应商";
      case "option2":
        return "在洽谈合作意向的第三方";
      case "option3":
        return "政府部门或机构";
      case "option4":
        return "顾客";
      case "option5":
        return "其他（比如公司内部人员）";
      default:
        return "";
    }
  };

  getHandleTypeTitle = (provider) => {
    switch (provider.key) {
      case "option1":
        return "退回给提供方";
      case "option2":
        return "申报人保留";
      case "option3":
        return "上交给直线经理";
      case "option4":
        return "上交给合规办公室";
      case "option5":
        return "捐给麦当劳叔叔之家";
      case "option6":
        return "其他";
      default:
        return "";
    }
  };

  getGiftTypeTitle = (value) => {
    switch (value.key) {
      case "option1":
        return "现金及现金等价物（如预充值的会员卡、代币卡（实体卡、电子礼券）";
      case "option2":
        return "实物";
      case "option3":
        return "财产性利益（如房屋装修、旅游费用等）";
      case "option4":
        return "其他";
      default:
        return "";
    }
  };

  getObtainChannel = (vlaues) => {
    if (vlaues.length === 0) return "";
    const relative = vlaues[0];
    switch (relative.key) {
      case "option1":
        return "招待/招商会等";
      case "option2":
        return "邮件/快递";
      case "option3":
        return "当面交付";
      case "option4":
        return "其他";
      default:
        return "";
    }
  };

  giftProviderHaveProjectsTitle = (values) => {
    if (values.length === 0) return "";
    const relative = values[0];
    switch (relative.key) {
      case "option1":
        return "有";
      case "option2":
        return "没有";
      case "option3":
        return "不清楚";
      case "option4":
        return "其他";
      default:
        return "";
    }
  };

  render() {
    const { value } = this.props;
    console.log("gift declare detail", value);
    if (!value) {
      return (
        <Card
          style={{
            textAlign: "center",
          }}
        >
          <Spin />
        </Card>
      );
    }
    return (
      <div className="GiftDeclareDetail">
        <Card title="礼品/招待的具体信息" className="card-detail">
          <Row className="custom-form-row">
            {value.giftType2.map((item) => {
              return (
                <Col className="field-container" span={8} key={item.key}>
                  <div className="field-name" style={{ paddingRight: 8 }}>
                    {this.getGiftTypeTitle(item)}
                  </div>
                  <div>{item.slot}</div>
                </Col>
              );
            })}
            <Col className="field-container" span={8}>
              <div className="field-name" style={{ paddingRight: 8 }}>
                接收礼品/招待的日期
              </div>
              <div>{value.giftDate.format("YYYY-MM-DD")}</div>
            </Col>

            <Col className="field-container" span={8}>
              <div className="field-name" style={{ paddingRight: 8 }}>
                礼品/招待（预估）价值
              </div>
              <div>{formatNumber((Number(value.giftPrice) || 0).toFixed(2))}</div>
            </Col>
            <Col className="field-container" span={8}>
              <div className="field-name" style={{ paddingRight: 8 }}>
                最近12个月内这是第几次
              </div>
              <div>{value.singleProviderGiftDescription2_5_1}</div>
            </Col>
            <Col className="field-container" span={8}>
              <div className="field-name" style={{ paddingRight: 8 }}>
                最近12个月礼品/招待金额累计大约为
              </div>
              <div>
                {formatNumber((
                  Number(value.singleProviderGiftDescription2_5_2) || 0
                ).toFixed(2))}
              </div>
            </Col>
          </Row>
        </Card>
        <Card style={{ marginTop: 16 }} title="礼品/招待提供方信息">
          {value.providerType1.map((provider) => {
            return (
              <Card
                className="antd-card-inner"
                title={this.getProviderTitle(provider)}
                key={provider.key}
                style={{ marginBottom: 16 }}
              >
                <UnifiedTable
                  showIndex
                  readonly
                  exportFile={false}
                  importFile={false}
                  cellMinWidth={100}
                  formField={JSON.stringify(
                    provider.key === "option4"
                      ? formFieldOfCustomer
                      : formFieldOfProvider
                  )}
                  value={provider.slot}
                ></UnifiedTable>
              </Card>
            );
          })}
        </Card>
        <Card style={{ marginTop: 16 }} title="礼品/招待处理情况">
          <Card>
            {value.giftHandleType2_4.map((handleType, index) => {
              return (
                (handleType.slot.fileList.length > 0 || handleType.slot.message) && <div key={handleType.key}>
                  <div style={{ marginBottom: 20 }}>
                    {this.getHandleTypeTitle(handleType)}
                  </div>
                  <Row>
                    <Col span={8}>
                      {handleType.slot && `具体信息：${handleType.slot.message}`}
                    </Col>
                    {["option1", "option2", "option3", "option4", "option5", "option6"].includes(
                      handleType.key
                    ) && (
                      <Col span={8}>
                        <div>附件{handleType.slot && handleType.slot.fileList && handleType.slot.fileList.length ? '' : ': 无'}</div>
                        <div>
                          {handleType.slot &&
                            handleType.slot.fileList &&
                            handleType.slot.fileList.map((file, index) => {
                              return (
                                <div key={file.fileURL}>
                                  <a href={file.fileURL} target="_blank">
                                    附件{index + 1}
                                  </a>
                                </div>
                              );
                            })}
                        </div>
                      </Col>
                    )}
                  </Row>
                  {index < value.giftHandleType2_4.length - 1 && (
                    <Divider></Divider>
                  )}
                </div>
              );
            })}
          </Card>
        </Card>
        <Card style={{ marginTop: 16 }} title="其他">
          <Card>
            <div>
              <div style={{ marginBottom: 20 }}>
                礼品/招待的接收者和提供礼品/招待的提供方是否为亲属关系：&nbsp;
                <b>
                  {value.giftProviderHaveRelatives.find(
                    (item) => item.key === "option1"
                  )
                    ? "是"
                    : "否"}
                </b>
              </div>
              {value.giftProviderHaveRelatives.map((item) => {
                return <div key={item.key}>{item.slot ? `具体信息：${item.slot}` : ''}</div>;
              })}
            </div>
            <Divider></Divider>

            {this.getObtainChannel(value.giftObtainChannel) !== '' && <div>
              <div style={{ marginBottom: 20 }}>
                礼品/招待获取的渠道：&nbsp;
                <b>{this.getObtainChannel(value.giftObtainChannel)}</b>
              </div>
              {value.giftObtainChannel.map((item) => {
                return (
                  <div key={item.key}>
                    {(() => {
                      if (item.key === "option1") {
                        return (
                          <Row>
                            <Col span={8}>{item.slot.message}</Col>
                            <Col span={8}>
                              <div>附件</div>
                              <div>
                                {item.slot.fileList.map((file, index) => {
                                  return (
                                    <div key={file.fileURL}>
                                      <a href={file.fileURL} target="_blank">
                                        附件{index + 1}
                                      </a>
                                    </div>
                                  );
                                })}
                              </div>
                            </Col>
                          </Row>
                        );
                      } else if (item.key === "option4") {
                        return '具体信息：' + item.slot;
                      }
                      return null;
                    })()}
                  </div>
                );
              })}
            </div>}
            <Divider></Divider>

            {this.giftProviderHaveProjectsTitle(value.giftProviderHaveProjects) !== '' && <div>
              <div style={{ marginBottom: 20 }}>
                礼品/招待提供方或其所在公司目前是否有和公司正在进行的项目：&nbsp;
                <b>
                  {this.giftProviderHaveProjectsTitle(
                    value.giftProviderHaveProjects
                  )}
                </b>
              </div>
              {value.giftProviderHaveProjects.map((item) => {
                return (
                  <div key={item.key}>
                    {(() => {
                      if (item.key === "option1" || item.key === "option4") {
                        return '具体信息：' + item.slot;
                      }
                      return null;
                    })()}
                  </div>
                );
              })}
            </div>}
          </Card>
        </Card>

        {/* <pre>{JSON.stringify(value, null, 2)}</pre> */}
      </div>
    );
  }
}

export default GiftDeclareDetail;
